﻿using System;
using System.Windows.Forms;
using Finance.GUI;

namespace Finance.Views
{
	internal partial class FormDocument : FormOkCancel
	{
		public FormDocument()
		{
			InitializeComponent();
			UpdateControlSize();
		}

		private Control _control;

		public Control Control
		{
			set
			{
				if (_control != null)
				{
					Controls.Remove(_control);
					_control.Dispose();
				}

				_control = value;

				if (_control != null)
				{
					Controls.Add(_control);	
					_control.Dock = DockStyle.Fill;
				}
			}
		}
        
		private void OnInputPanelEnabledChanged(object sender, EventArgs e)
		{
			UpdateControlSize();
		}

		private void UpdateControlSize()
		{
			if (_control == null)
				return;

			if (inputPanel1.Enabled)
			{
				_control.Dock = DockStyle.Top;
				_control.Height = inputPanel1.VisibleDesktop.Height;
			}
			else
			{
				_control.Dock = DockStyle.Fill;
			}
		}
	}

}